<template>
	<view class="page login xc-relative xc-bg-f1f1f1" style="height: calc(100vh);overflow: hidden;">
		<view class="top xc-w-100p flex justify-center align-center"
			style="background-image: url(../../static/login/bj.png);">
			<view class="logo flex align-center justify-center">
				<image style="width:184rpx;height:184rpx;" class="xc-radius-1000" :src="config.logo" mode />
			</view>
		</view>

		<view class="form xc-flex xc-flex-column align-center xc-padding-20">
			<view class="xc-c-666 xc-margin-b-15">你尚未登录，登录后该应用将获得以下权限</view>
			<view class="xc-c-666">
				<text class="cuIcon-title xc-text-12 xc-margin-r-10"></text>
				<text class="xc-text-12">获得你的公开信息(昵称、头像等)</text>
			</view>
		</view>

		<!-- 登录按钮 -->
		<view class="submit xc-w-100p xc-padding-lr-20">
			<button open-type="getUserInfo" @getuserinfo="getUserInfo"
				class="xc-w-100p xc-radius-100 xc-margin-b-20 xc-c-fff xc-bg-1563FF">确认授权登录</button>
			<button @click="goRoute('nb')" class="xc-radius-100 xc-w-100p xc-margin-b-20 xc-c-fff xc-bg-1563FF">返回</button>
		</view>
	</view>
</template>
<script>
	// import util from "@/common/util.js";
	export default {
		components: {},
		data() {
			return {
				logoSrc: "",
				auth_mobile: false,
				encryptedData: "",
				iv: "",

				config: {},
				templateAll:`
				<template>
					<view class="page login xc-relative xc-bg-f1f1f1" style="height: calc(100vh);overflow: hidden;">
						<view class="top xc-w-100p flex justify-center align-center"
							style="background-image: url(../../static/login/bj.png);">
							<view class="logo flex align-center justify-center">
								<image style="width:184rpx;height:184rpx;" class="xc-radius-1000" :src="config.logo" mode />
							</view>
						</view>
				
						<view class="form xc-flex xc-flex-column align-center xc-padding-20">
							<view class="xc-c-666 xc-margin-b-15">你尚未登录，登录后该应用将获得以下权限</view>
							<view class="xc-c-666">
								<text class="cuIcon-title xc-text-12 xc-margin-r-10"></text>
								<text class="xc-text-12">获得你的公开信息(昵称、头像等)</text>
							</view>
						</view>
				
						<!-- 登录按钮 -->
						<view class="submit xc-w-100p xc-padding-lr-20">
							<button open-type="getUserInfo" @getuserinfo="getUserInfo"
								class="xc-w-100p xc-radius-100 xc-margin-b-20 xc-c-fff xc-bg-1563FF">确认授权登录</button>
							<button @click="goRoute('nb')" class="xc-radius-100 xc-w-100p xc-margin-b-20 xc-c-fff xc-bg-1563FF">返回</button>
						</view>
					</view>
				</template>
				<script>
					// import util from "@/common/util.js";
					export default {
						components: {},
						data() {
							return {
								logoSrc: "",
								auth_mobile: false,
								encryptedData: "",
								iv: "",
				
								config: {},
							};
						},
						onLoad() {
							// this.logoSrc = uni.getStorageSync('sys_config').logo;
							this.getOpenConfig();
						},
						onShow() {},
						mounted() {},
						methods: {
							getOpenConfig() {
								this.$api.open_config().then((data) => {
									this.config = data;
								});
							},
							// 
							getUserInfo(e) {
								var that = this;
								var info = e.target.userInfo;
								// 注册
								uni.login({
									provider: "weixin",
									success(l) {
										let param = {};
										param["code"] = l.code;
										param["nickName"] = info.nickName;
										param["avatarUrl"] = info.avatarUrl;
										param["gender"] = info.gender;
										let referral_id = uni.getStorageSync("referral_id"); //推荐人
										param["referral_id"] = referral_id || "";
										let shop_id = uni.getStorageSync("shop_id"); //扫门店二维码
										param["shop_id"] = shop_id || "";
										that.$api.passport_register(param).then((data) => {
											that.$api.setStorage(data.data);
											uni.removeStorageSync('referral_id'); //成功后删掉推荐人
											let {
												business_info
											} = data.data;
											if (business_info.type === 2) {
				
												that.goRoute("rl", "/pages/installer/installer");
												return;
											}
											uni.navigateBack();
										});
									},
								});
							},
						},
					};
				</ script>
				<style lang="scss" scoped>
					uni-page-body {
						width: 100%;
						height: 100%;
					}
				
					.page {
						width: 100%;
						height: 100%;
					}
				
					// .login {
					// 	.submit{
					// 		position: absolute;
					// 		top: 48%;
					// 	}
					// }
					// logo
					.login {
						.top {
							.logo {
								width: 184rpx;
								height: 184rpx;
								background: #fff;
								border-radius: 100%;
							}
				
							height: 459rpx;
							// background-image: url(../../static/login/bj.png);
						}
				
						.title {
							.active {
								>view {
									display: inline-block;
									width: 28rpx;
									height: 6rpx;
								}
				
								>text {
									font-weight: bold;
									color: $u-type-primary;
									font-size: 44rpx;
								}
							}
				
							>view {
								display: flex;
								flex-direction: column;
								height: 160rpx;
								margin-left: 80rpx;
								align-items: center;
								justify-content: center;
							}
						}
					}
				</style>
				`
			};
		},
		onLoad() {
			// this.logoSrc = uni.getStorageSync('sys_config').logo;
			this.getOpenConfig();
		},
		onShow() {},
		mounted() {},
		methods: {
			getOpenConfig() {
				this.$api.open_config().then((data) => {
					this.config = data;
				});
			},
			// 
			getUserInfo(e) {
				var that = this;
				var info = e.target.userInfo;
				// 注册
				uni.login({
					provider: "weixin",
					success(l) {
						let param = {};
						param["code"] = l.code;
						param["nickName"] = info.nickName;
						param["avatarUrl"] = info.avatarUrl;
						param["gender"] = info.gender;
						let referral_id = uni.getStorageSync("referral_id"); //推荐人
						param["referral_id"] = referral_id || "";
						let shop_id = uni.getStorageSync("shop_id"); //扫门店二维码
						param["shop_id"] = shop_id || "";
						that.$api.passport_register(param).then((data) => {
							that.$api.setStorage(data.data);
							uni.removeStorageSync('referral_id'); //成功后删掉推荐人
							let {
								business_info
							} = data.data;
							if (business_info.type === 2) {

								that.goRoute("rl", "/pages/installer/installer");
								return;
							}
							uni.navigateBack();
						});
					},
				});
			},
		},
	};
</script>
<style lang="scss" scoped>
	uni-page-body {
		width: 100%;
		height: 100%;
	}

	.page {
		width: 100%;
		height: 100%;
	}

	// .login {
	// 	.submit{
	// 		position: absolute;
	// 		top: 48%;
	// 	}
	// }
	// logo
	.login {
		.top {
			.logo {
				width: 184rpx;
				height: 184rpx;
				background: #fff;
				border-radius: 100%;
			}

			height: 459rpx;
			// background-image: url(../../static/login/bj.png);
		}

		.title {
			.active {
				>view {
					display: inline-block;
					width: 28rpx;
					height: 6rpx;
				}

				>text {
					font-weight: bold;
					color: $u-type-primary;
					font-size: 44rpx;
				}
			}

			>view {
				display: flex;
				flex-direction: column;
				height: 160rpx;
				margin-left: 80rpx;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>